package com.iwuke.dance.wallet;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.activity.WebViewActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.http_request.Bean;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.SharedPreferencesUtil;
import com.iwuke.dance.util.ToastUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;

import java.io.Serializable;
import java.util.HashMap;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/9/15
 * 身份信息
 */
public class IdentityInformationActivity extends BaseActivity implements View.OnClickListener {

    private TitleBarView title_bar;
    private EditText et_name;
    private EditText et_id_number;
    private TextView tv_button;
    private ImageView image_circle;
    private TextView tv_user_agreement;
    private boolean check_box=false;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(IdentityInformationActivity.this,networkEvent,title_bar);

    }
    @Override
    protected int getView() {
        return R.layout.activity_identity_information;
    }

    @Override
    protected void init(View mView) {

        title_bar = findViewById(R.id.title_bar);

        //姓名
        et_name = findViewById(R.id.et_name);
        //证件号
        et_id_number = findViewById(R.id.et_id_number);

        //确认
        tv_button = findViewById(R.id.tv_button);
        //是否选中
        image_circle = findViewById(R.id.image_circle);
        //实名认证服务协议
        tv_user_agreement = findViewById(R.id.tv_user_agreement);

        title_bar.setTitleText(null);
        title_bar.setLeftOnClick(this);
        tv_button.setOnClickListener(this);
        //是否选中
        image_circle.setOnClickListener(this);
        //实名认证服务协议
        tv_user_agreement.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){
            finish();
        }else if (v.getId()==R.id.tv_button){

            String userName = et_name.getText().toString();
            String idCardNumber = et_id_number.getText().toString();

            if (TextUtils.isEmpty(userName)){
                ToastUtil.setToast(IdentityInformationActivity.this,"姓名不能为空哦！");
                return;
            }

            if (TextUtils.isEmpty(idCardNumber)||idCardNumber.length()<15||idCardNumber.length()>18){
                ToastUtil.setToast(IdentityInformationActivity.this,"姓名不能为空哦！");
                return;
            }

            if (!check_box){
                ToastUtil.setToast(IdentityInformationActivity.this,"请阅读并且选中《实名认证服务协议》");
                return;
            }

            HashMap<String, Object> map = new HashMap<>();
            map.put("userId", SharedPreferencesUtil.getInstance().getUserId());
            map.put("userName",userName);
            map.put("idCardNumber",idCardNumber);

            PathUrl.createByRealName(map, new PathUrl.DataCallBack<Bean>() {
                @Override
                public void onSucess(Bean bean) {
                    if (bean!=null) {
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("data", (Serializable)bean);
                        Util.setIntent(IdentityInformationActivity.this, SetPaymentPasswordActivity.class, bundle);
                        finish();
                    }
                }

                @Override
                public void onFail(String errorCode) {
                    ToastUtil.setToast(IdentityInformationActivity.this,errorCode);
                }
            });


        }else if (v.getId()==R.id.image_circle){
            //是否选中
            if (check_box){
                //不选中
                //img_check_box.setImageResource(R.drawable.bg_radius7_white_shape);
                image_circle.setColorFilter(getResources().getColor(R.color.color_ccc,null));
//                image_circle.setImageResource(R.mipmap.img_circle);
                check_box = false;
            }else {
                //选中
                image_circle.setColorFilter(getResources().getColor(R.color.color_5ed,null));
//                image_circle.setImageResource(R.mipmap.img_check_box);
                check_box = true;
            }
        }else if (v.getId()==R.id.tv_user_agreement){
            //实名认证服务协议
            Util.setIntent(IdentityInformationActivity.this, WebViewActivity.class,"https://www.baidu.com");

        }
    }
}
